home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / misc / emu / Apex-src.lha / SERHANA.68K < prev    next >
Text File  |  2001-09-30  |  4KB  |  145 lines

  1. ;SERHANA.68K    SEP-01-88    (Also see INFOSTR)
  2. ;RS-232 handler.
  3. ; by Loren Blaney
  4. ;
  5. ;REVISION HISTORY:
  6. ;MAR-03-88, Based on MAR-09-87 version of XMODEMA.68K
  7. ;JUL-07-88, Changed memory location
  8. ;SEP-01-88, Changed memory location and whittled off a few bytes.
  9.  
  10.     NOLIST
  11.     INCLUDE    SYSPAG        ;Get the system page difinitions
  12.     LIST
  13.  
  14. DEVNUM    EQU    4        ;Install this handler as device # 4
  15.  
  16.     ORG    $F26
  17. START    EQU    @        ;Address where this handler starts
  18.  
  19. ;=======================================================================
  20. ;ENTRY POINTS:
  21. ;
  22. SERHANA    DC.L    OPENI        ;$00 = OPENI
  23.     DC.L    OPENO        ;$04 = OPENO
  24.     DC.L    CHIN        ;$08 = CHIN
  25.     DC.L    CHOUT        ;$0C = CHOUT
  26.     DC.L    CLOSE        ;$10 = CLOSE
  27.     DC.L    GETINFO        ;$14 = GETINFO
  28.  
  29. ;-----------------------------------------------------------------------
  30. ;OPEN (INITIALIZE) THE RS-232 PORT AND SET THE INPUT BUFFER TO EMPTY
  31. ;
  32. OPENI    BSR.S    OPEN        ;Init RS-232 port for I/O, set baud rate
  33.     BRA.S    FLUSH        ;(PBRA) Flush out bytes in receive FIFO
  34.  
  35. ;-----------------------------------------------------------------------
  36. ;Open (initialize) the RS-232 port.
  37. ;
  38. OPENO    BSR.S    OPEN        ;Init RS-232 port for I/O, set baud rate
  39.     BRA.S    FLUSH        ;(PBRA) Flush out bytes in receive FIFO
  40.  
  41. ;-----------------------------------------------------------------------
  42. ;Get a character from the serial port and return it in D0.
  43. ;
  44. CHIN    BRA.S    BYTEIN        ;(PBRA)
  45.  
  46. ;-----------------------------------------------------------------------
  47. ;Output the byte in D0 to the buffered RS-232 port.
  48. ;
  49. CHOUT    BRA    BYTEOUT        ;(PBRA)
  50.  
  51. ;-----------------------------------------------------------------------
  52. ;Close the serial port.
  53. ;
  54. CLOSE    RTS
  55.  
  56. ;-----------------------------------------------------------------------
  57. ;RETURN THE ADDRESS OF THE INFORMATION ARRAY IN D0
  58. ;
  59. GETINFO    MOVE.L    #INFO,D0
  60. DUMMY    RTS
  61.  
  62. INFO    DC.L    START        ;START AND END ADDRESSES OF THIS HANDLER
  63.     DC.L    END
  64.     DC.L    INFOSTR        ;DESCRIPTION
  65. INFOSTR    ASCII    'SERHANA   SEP-01-88  RS-232 handler, 1200 baud'
  66.     DC.B    0
  67.  
  68. ;======================================================================
  69. ;LOWEST LEVEL I/O ROUTINES:
  70. ;
  71. SERDATR    EQU    $DFF018        ;Serial port data and status register
  72. SERDAT    EQU    $DFF030        ;Serial port data register (write)
  73. SERPER    EQU    $DFF032        ;Serial port period and control register
  74. INTREQ    EQU    $DFF09C        ;Interrupt request (status) bits
  75.  
  76. ;----------------------------------------------------------------------
  77. ;Routine to initialize RS-232 I/O.
  78. ; N = 1E9 /(baud rate * 279.4) -1
  79. ; (Max N = 16383, Min baud = 109)
  80. ; 1E9 /(300 * 279.4) -1 = 11929
  81. ; 1E9 /(19200 * 279.4) -1 = 185 
  82. ; 1E9 /(1200 * 279.4) -1 = 2982
  83. ;
  84. N    EQU    2982
  85. OPEN    MOVE.W    #N,SERPER.L    ;Set 8 bits (bit 15 is clear)
  86.     MOVE.W    #$0800,INTREQ.L    ;Clear "receive buffer full" status bit
  87.     RTS
  88.  
  89. ;-----------------------------------------------------------------------
  90. ;Flush out any characters in the receive FIFO.
  91. ;
  92. FLUSH    MOVE.L    D0,-(SP)    ;Save D0
  93.  
  94. FL10    MOVE.W    SERDATR.L,D0    ;Read status and data
  95.     BTST    #14,D0        ;Receive buffer full
  96.     BEQ.S    FL90        ;Branch if not -- exit
  97.  
  98.     MOVE.W    #$0800,INTREQ.L    ;Clear "receive buffer full" status bit
  99.     BRA.S    FL10        ;Loop until all bytes flushed
  100.  
  101. FL90    MOVE.L    (SP)+,D0    ;Restore D0
  102.     RTS
  103.  
  104. ;-----------------------------------------------------------------------
  105. ;Get a byte from the RS-232 port and return it in D0.
  106. ;
  107. BYTEIN
  108. BYIN10    MOVE.W    SERDATR.L,D0    ;Read status and data
  109.     BTST    #14,D0        ;Receive buffer full?
  110.     BEQ.S    BYIN10        ;Branch if not -- loop
  111.  
  112.     MOVE.W    #$0800,INTREQ.L    ;Clear "receive buffer full" status bit
  113.     ANDI.L    #$000000FF,D0    ;Return byte in D0
  114.     RTS
  115.  
  116. ;----------------------------------------------------------------------
  117. ;Routine to output the byte in D0 to an RS-232 port.
  118. ;
  119. BYTEOUT    MOVEM.W    D0-D1,-(SP)    ;Save low word of registers
  120.  
  121. BYO10    MOVE.W    SERDATR.L,D1    ;Get serial port status
  122.     BTST    #13,D1        ;Test transmitter buffer empty
  123.     BEQ.S    BYO10        ;Branch if it is not empty
  124.  
  125.     ANDI.W    #$00FF,D0    ;Add start and stop bits to the
  126.     ORI.W    #$0100,D0    ; data byte
  127.     MOVE.W    D0,SERDAT.L    ;Output data
  128.  
  129.     MOVEM.W    (SP)+,D0-D1    ;Restore registers
  130.     RTS
  131.  
  132.  
  133. END    EQU    @ -1        ;ADDRESS WHERE THIS HANDLER ENDS
  134.     IF    END > $1000
  135.     ERROR -- FILE IS TOO LONG
  136.     ENDIF
  137.  
  138. ;-----------------------------------------------------------------------
  139. ;HOOK THIS HANDLER INTO THE DEVICE HANDLER TABLE
  140. ;
  141.     ORG    4 *DEVNUM +DEVTBL
  142.     DC.L    SERHANA
  143.  
  144.     END
  145. -----